package com.demo.designmode.singleton;

/**
 * @Author: jxm
 * @Description: 懒汉式-方式1（线程不安全）
 * @Date: 2023-11-15 10:57
 * @Version: 1.0
 */
public class LazySingleton1 {

    //私有构造方法
    private LazySingleton1() {}

    //在成员位置创建该类的对象
    private static LazySingleton1 instance;

    //对外提供静态方法获取该对象
    public static LazySingleton1 getInstance() {
        if(instance == null) {
            instance = new LazySingleton1();
        }
        return instance;
    }

    public static void main(String[] args) {
        for (int i =0;i<10;i++){
            new Thread(()->{
                LazySingleton1 instance = LazySingleton1.getInstance();
                System.out.println(Thread.currentThread().getName()+"=="+instance.hashCode());
            }).start();
        }
    }
}
